package com.example.woke;

import java.util.ArrayList;

import com.http.HttpMethods;
import com.zhongcai.online.R;
import com.woke.method.MyApp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebSettings.TextSize;
import android.widget.TextView;

public class YuqiActivity extends Activity {

	private WebView mWebView;
	private ArrayList<String> list;
	private MyApp application;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_yuqi);
		
		application = (MyApp) getApplication();
		list = getIntent().getStringArrayListExtra("list");
//		Log.e("list", ""+list);
		intview();
		
	}
	
	private void setSettings(WebSettings settings) {
		settings.setJavaScriptEnabled(true);// ���ÿ�������JS�ű�
		settings.setDefaultTextEncodingName("UTF-8");
		settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		mWebView.setBackgroundColor(getResources().getColor(R.color.white)); // ���ñ���ɫ  
//		mWebView.getBackground().setAlpha(50); // �������͸���� ��Χ��0-255 
		settings.setSupportZoom(false);// ��������webview�Ŵ�
		settings.setBuiltInZoomControls(false);
		settings.setDomStorageEnabled(true);
		settings.setTextSize(TextSize.NORMAL);
//		settings.setPluginState(PluginState.ON);
		settings.setDatabaseEnabled(true);
	}

	// jsͨ�Žӿ�
	public class JavascriptInterface {

		private Context context;
		Intent intent = new Intent();

		public JavascriptInterface(Context context) {
			this.context = context;
		}
		public void thisImage(String index){
			intent.putExtra("index", index);
		}
	}
	// ����
	private class MyWebViewClient extends WebViewClient {
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			return super.shouldOverrideUrlLoading(view, url);
		}
		@Override
		public void onPageFinished(WebView view, String url) {
			view.getSettings().setJavaScriptEnabled(true);
			mWebView.setVisibility(View.VISIBLE);
			super.onPageFinished(view, url);
		}

		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			view.getSettings().setJavaScriptEnabled(true);
			super.onPageStarted(view, url, favicon);
		}

		@Override
		public void onReceivedError(WebView view, int errorCode,
				String description, String failingUrl) {
			super.onReceivedError(null, 1, "访问失败", null);
		}
	}

	private class MyWebChromeClient extends WebChromeClient {
		@Override
		public void onProgressChanged(WebView view, int newProgress) {
			super.onProgressChanged(view, newProgress);
		}
		
		@Override
		public void onReceivedTitle(WebView view, String title) {
			super.onReceivedTitle(view, title);
		}
		
		@Override
		public void onReceivedTouchIconUrl(WebView view, String url,
				boolean precomposed) {
			super.onReceivedTouchIconUrl(view, url, precomposed);
		}
	}
	

	private void intview() {
		TextView mTtilt = (TextView) findViewById(R.id.avyuqi_text_title);
		if(list.size() > 1){
			mTtilt.setText("借款协议");
		}
		mWebView = (WebView) findViewById(R.id.webView1);
		
		findViewById(R.id.avyuqi_image_back).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		WebSettings settings = mWebView.getSettings();
		setSettings(settings);
		
//		settings.setPluginsEnabled(true); // ֧�ֲ�� 
//		mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
		// ���js�����ӿ��࣬������� imagelistner
//		mWebView.addJavascriptInterface(new JavascriptInterface(
//				getApplicationContext()), "imagelistner");
		mWebView.setWebChromeClient(new MyWebChromeClient());
		mWebView.setWebViewClient(new MyWebViewClient());
//		mWebView.loadUrl("http://www.youku.com/");
		if(list.size() > 1) {
			if (application.getDatas_load () != null) {
				mWebView.loadUrl (HttpMethods.BASEURL + "g=api&m=quota&a=protocol&user_id="
						+ application.getDatas_load ()
						.getId () + "&money=" + list.get (1) + "&nianll=" + list.get (0) + "&hkdate=" + list
						.get (2));
//			Log.e("!!", "!!"+Contants.BASEURL+"g=api&m=quota&a=protocol&user_id="
//					+application.getuser_id()+"&money="+list.get(1)+"&nianll="+list.get(0)+"&hkdate="+list.get(2));
			} else {
				mWebView.loadUrl (HttpMethods.BASEURL + "g=api&m=quota&a=overdue");

			}
		}
	}
}
